//
//  BaseViewController.swift
//  SwiftSina
//
//  Created by Jason Ding on 16/8/17.
//  Copyright © 2016年 Jason Ding. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    var isLogin:Bool = true
    lazy var visitorView = VisitorView.visitorView()
    
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }


}
extension BaseViewController{
    private func setupVisitorView(){
        view = visitorView
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewController.registerItemClick), forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginItemClick), forControlEvents: .TouchUpInside)
        
        setupNavgationitems()
    }
    
    /// 设置导航条items
    private func setupNavgationitems(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(BaseViewController.registerItemClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(BaseViewController.loginItemClick))
    }
}

// MARK:- 实践监听
extension BaseViewController{
    @objc private func registerItemClick() {
        print(#function)
    }
    @objc private func loginItemClick() {
        print(#function)

    }
}
